#tag Class
Protected Class HistoryClass
	#tag Method, Flags = &h0
		Sub Add(URL as String)
		  Dim maxHist as Integer
		  If Not fromHistory then    // URL didn't come from Back/Fwd buttons so add to history
		    historyList.append URL
		    maxHist = ubound(historyList)
		    if maxHist > 100 then  //Restrict length of history array
		      historyList.remove(0)
		      maxHist = maxHist - 1
		    End If
		    historyPos = maxHist  //Remember where we are in history list (at the end)
		    mValidFwd= False //We're at the end of history list, so Fwd is invalid
		  End If
		  if historyPos > 0 then  //We're not at start of history, so Back is valid
		    mValidBack = True
		  End If
		  fromHistory = false  // We've finished doing Back or Forward, if we were doing them
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function Back() As String
		  if historyPos > 0 Then
		    historyPos = historyPos - 1
		    fromHistory = True    //Flag that we're in history - don't need to remember URL again
		    mValidFwd = True  //There must now be somewhere to go forward to
		    if historyPos < 1 Then  //We've gone all the way back
		      mValidBack = False  //So Back is invalid
		    End If
		  End If
		  Return historyList(historyPos)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function Fwd() As String
		  Dim maxHist as Integer
		  maxHist = ubound(historyList)
		  if historyPos < maxHist Then //There's somewhere Forward to go
		    historyPos = historyPos + 1
		    fromHistory = True    //Flag that we're in history - don't need to remember URL again
		    //HTMLViewer1.LoadURL historyList(historyPos)
		    if historyPos >= maxHist Then //We've gone right to the end
		      mValidFwd = False  //So Fwd is now invalid
		    End If
		  End If
		  Return historyList(historyPos)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function validBack() As Boolean
		  Return mValidBack
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function validFwd() As Boolean
		  Return mValidFwd
		End Function
	#tag EndMethod


	#tag Property, Flags = &h21
		Private fromHistory As Boolean
	#tag EndProperty

	#tag Property, Flags = &h21
		Private historyList() As String
	#tag EndProperty

	#tag Property, Flags = &h21
		Private historyPos As Integer
	#tag EndProperty

	#tag Property, Flags = &h21
		Private mValidFwd As Boolean
	#tag EndProperty

	#tag Property, Flags = &h21
		Private mValidBack As Boolean
	#tag EndProperty

	#tag Property, Flags = &h0
		#tag Note
			Saves previous address to be redisplayed if new link is cancelled,
			even if Back/Fwd buttons were used
		#tag EndNote
		prevAddressBar As String
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="prevAddressBar"
			Group="Behavior"
			Type="String"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
